package com.atung.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atung.request.RequestIdentityVerification;
import com.atung.response.ResponeRefundDetails;
import com.atung.response.ResponeRefundDetailsIng;
import com.atung.response.ResponeVerificationIdentity;
import com.atung.response.ResponseBusOrderCarList;
import com.atung.service.BusOrderCarService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yuyi.full.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/car/order")
@Api(tags="订单模块")
public class BusOrderController {

	@Autowired
	private BusOrderCarService busOrderCarService;
	
	@ApiOperation("订单列表")
	@GetMapping("/getOrderList")
	public Result getCarOrderList(@RequestParam("openId")String openId,
			@RequestParam(required=false) Integer orderState,
			@RequestParam(required=false,defaultValue="1")Integer pageNum,
			@RequestParam(required=false,defaultValue="10")Integer pageSize){		
		PageHelper.startPage(pageNum, pageSize);
		List<ResponseBusOrderCarList> ResponseBusOrderCarList=busOrderCarService.getOrderList(openId, orderState);
		PageInfo<ResponseBusOrderCarList>piHelper=new PageInfo<>(ResponseBusOrderCarList);
		
		return Result.success(piHelper);
		
	}	
	@GetMapping("/orderDetails")
	@ApiOperation("订单详情")
	public Result orderDetails(@RequestParam Long orderId){
		
		return Result.success(busOrderCarService.getOrderDetails(orderId));
	}
	@GetMapping("/refund/details")
	@ApiOperation("退款详情")
	public Result<ResponeRefundDetails>refundDetails(@RequestParam Long orderId) throws Exception{
		ResponeRefundDetails response=busOrderCarService.refundDetails(orderId);
		return Result.success(response);
	}
	@GetMapping("/refund/detailsing")
	@ApiOperation("退款中详情")
	public Result<ResponeRefundDetailsIng> refundDetailsing(@RequestParam Long orderId){
		ResponeRefundDetailsIng response=busOrderCarService.refundDetailsIng(orderId);
		return Result.success(response);
	}
	
	@PostMapping
	@ApiOperation("身份验证")
	public Result<ResponeVerificationIdentity>identityVerification(@RequestBody RequestIdentityVerification request){
		//select * from bus_car_ride bcr inner join bus_order_car boc on bcr.order_id=boc.id where bcr.allocation_id=1  and bcr.ride_code =1 and bcr.is_delect=0 and boc.order_state BETWEEN 301 and 303
		ResponeVerificationIdentity response;
		try {
			response = busOrderCarService.identityVerification(request);
			return Result.success(response);
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			return Result.error(201, e.getMessage());
		}
		
	}

	
}
